package HuaWeiPractice;

public class SqlReplaceAll {
    public static void main(String[] args) {
        String[] area_code = new String[]{"552", "553"};
        String sql1 = "select " +
                " t.latn_id," +
                " t.prod_inst_id,"
                + " t.acc_num  " +
                " from sql0 t,bss.PROD_INST_SUB_s_551 m " +
                " where m.status_cd='100000' "
                + " and m.prod_id='794527034' "//5G SA功能ID
                + " and t.latn_id='551' "
                + " and t.prod_inst_id=m.ACC_PROD_INST_ID  ";

        String sql2 = sql1;
        //替换sql1中551为 area_code并将全部sql1全关联成为sql2
        for (int i = 0; i < area_code.length; i++) {
            sql2 += " union all " + sql1.replaceAll("551", area_code[i]);
            System.out.println("============================================================================");
            System.out.println("这是sql2的：\n"+sql2);
        }
        System.out.println("\n");
        String sql3 = "select latn_id,prod_inst_id,acc_num from " + "("+sql2+")" +" t" + " group by latn_id,prod_inst_id,acc_num ";

        System.out.println("######这是sql3######\n" + sql3);
    }
}
